package com.xxg.renrensearch.controller;

import com.xxg.renrensearch.domain.query.GetCategoryQuery;
import com.xxg.renrensearch.domain.result.BaseResult;
import com.xxg.renrensearch.domain.result.CategoryResult;
import com.xxg.renrensearch.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资源管理接口
 *
 * @author xuxiaogang
 * @date 2021-11-24
 */
@Api(tags = "资源接口")
@RestController
@RequestMapping("/resource")
public class ResourceController {
    private final ResourceService resourceService;

    public ResourceController(ResourceService resourceService) {
        this.resourceService = resourceService;
    }

    @ApiOperation("获取城市列表")
    @RequestMapping(value = "getCityResource", method = RequestMethod.GET)
    public BaseResult<Object> getCityResource() {
        return resourceService.getCity();
    }

    @ApiOperation("根据店铺的商品分类信息")
    @RequestMapping(value = "getCategoryByShopId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE,
            consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "getCategoryQuery", value = "查询条件", required = true, dataType = "GetCategoryQuery")})
    public BaseResult<List<CategoryResult>> getCategoryByShopId(@RequestBody @Validated GetCategoryQuery getCategoryQuery) {
        return resourceService.getCategoryByShopId(getCategoryQuery.getShopId());
    }
}
